<template>
  <div class="app-container">
    <el-row >
      <el-col :span="6" :xs="24">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>{{$t('public.userProfile')}}</span>
          </div>
          <div>
            <div class="user-avatar-wrap">
              <userAvatar :user="user" />
            </div>
            <ul class="list-group list-group-striped">
              <li class="list-group-item">
                <svg-icon icon-class="user" />{{$t('userManage.userName')}}
                <div class="pull-right">{{ user.userName }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="phone" />{{$t('userManage.phone')}}
                <div class="pull-right">{{ user.phonenumber }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="email" />{{$t('userInfo.userMail')}}
                <div class="pull-right">{{ user.email }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="tree" />{{$t('userInfo.userdept')}}
                <div class="pull-right" v-if="user.dept">{{ user.dept.deptName }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="peoples" />{{$t('userInfo.userRole')}}
                <div class="pull-right">{{ roleGroup }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="date" />{{$t('public.createDate')}}
                <div class="pull-right">{{ user.createTime }}</div>
              </li>
            </ul>
          </div>
        </el-card>
      </el-col>
      <el-col style="padding-left:10px" :span="18" :xs="24">
          <el-tabs class="base-info" v-model="activeTab">
            <el-tab-pane :label="$t('userInfo.baseInfo')" name="userinfo">
              <userInfo :user="user" />
            </el-tab-pane>
            <el-tab-pane v-if="$store.getters.dataSource!=3" :label="$t('userInfo.modPass')" name="resetPwd">
              <resetPwd :user="user" />
            </el-tab-pane>
          </el-tabs>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import userAvatar from "./userAvatar";
import userInfo from "./userInfo";
import resetPwd from "./resetPwd";
import { getUserProfile } from "@/api/system/user";

export default {
  name: "Profile",
  components: { userAvatar, userInfo, resetPwd },
  data() {
    return {
      user: {},
      roleGroup: {},
      postGroup: {},
      activeTab: "userinfo"
    };
  },
  created() {
    this.getUser();
  },
  methods: {
    getUser() {
      getUserProfile().then(response => {
        this.user = response.data;
        this.roleGroup = response.roleGroup;
        this.postGroup = response.postGroup;
      });
    }
  }
};
</script>

<style lang="scss" scoped>

.app-container {
 padding:0;
 height: 100%;
}
.base-info{
  background-color: white;
  box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
  border-radius:4px;
  padding:0 10px;
  height: inherit;
}
::v-deep .el-row,::v-deep .el-col,::v-deep .el-card,{
  height: 100%;
}
::v-deep .el-card__header{
  padding: 7px 15px;
  font-size: 14px;
  line-height: 25px;
}
.user-avatar-wrap{
  text-align: center;
  margin: 20px 0 40px;
}
.list-group{
  color: #606266;
  .svg-icon{
    color: #a7a8b0;
    width:1em;
    height:1em;
    margin-right: 5px;
  }
}
</style>
